package com.mushuilingfeng.ddd.user.controller;

import com.mushuilingfeng.ddd.user.bo.UserRegisterBO;
import com.mushuilingfeng.ddd.user.service.IUserRegisterService;
import com.mushuilingfeng.spring.common.BaseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 沐水淋风
 * @date 2024/9/29
 */
@RestController
@RequestMapping("/userRegister")
@AllArgsConstructor
@Tag(name = "用户注册")
public class UserRegisterController {
    private final IUserRegisterService userRegisterService;
    
    @PostMapping("/sendRegisterVerifyCode/{tel}")
    @Operation(summary = "发送注册验证码")
    public BaseResult<Void> sendRegisterVerifyCode(@Parameter(description = "手机号", required = true) @PathVariable String tel) {
        userRegisterService.sendRegisterVerifyCode(tel);
        return BaseResult.success(null);
    }
    
    @PostMapping("/register")
    @Operation(summary = "注册")
    public BaseResult<Void> register(@RequestBody @Validated UserRegisterBO bo) {
        userRegisterService.register(bo);
        return BaseResult.success(null);
    }
    
    /**
     * 邀请注册
     *
     * @param bo         参数
     * @param inviteCode 邀请码
     * @return BaseResult
     */
    @PostMapping("inviteRegister/{inviteCode}")
    @Operation(summary = "邀请注册")
    public BaseResult<Void> inviteRegister(@RequestBody @Validated UserRegisterBO bo,
                                           @Parameter(description = "邀请码", required = true) @PathVariable String inviteCode) {
        userRegisterService.inviteRegister(bo, inviteCode);
        return BaseResult.success(null);
    }
    
}
